package com.gmall.rabbitmq.producer.controller;

import com.gmall.rabbitmq.config.RabbitMQConfig_Header;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("header")
public class HeaderExchangeController {

    @Autowired
    RabbitTemplate rabbitTemplate;
    @PostMapping("string1")
    public String producerMessage1(@RequestBody Map<String,String> map){

        rabbitTemplate.convertAndSend(RabbitMQConfig_Header.Exchange_Header_1,
                "","Hello 2109A",
                message -> {
                    message.getMessageProperties().setMessageId("123456");

                    map.forEach((key,value)->{
                        System.out.println("key:"+key+",value:"+value);
                        message.getMessageProperties().setHeader(key,value);
                    });

                    /*Set<String> keys = map.keySet();
                    for (String key : keys){
                        message.getMessageProperties().setHeader(key,map.get(key));
                    }*/
//                    message.getMessageProperties().setHeader("inform1","email");
//                    message.getMessageProperties().setHeader("inform2","sms");
                    return  message;
                });

        return "OK";
    }

}
